<template>
  <div>
    <el-button size="mini" type="primary" :icon="isView ? 'el-icon-more' : 'el-icon-edit'" @click="to" />
    <eForm ref="form" :sup-this="supThis" :is-add="false" :is-view="isView" />
  </div>
</template>
<script>
import eForm from './form'
export default {
  components: { eForm },
  props: {
    isView: {
      type: Boolean,
      required: true
    },
    data: {
      type: Object,
      required: true
    },
    supThis: {
      type: Object,
      required: true
    }
  },
  methods: {
    to() {
      const _this = this.$refs.form
      _this.getEqptStates()
      _this.getEqptSystem()
      _this.getEqptBrand()
      _this.form = {
        id: this.data.id,
        eqptsystem: this.data.eqptsystem && parseInt(this.data.eqptsystem),
        eqpttypeid: this.data.eqpttypeid && parseInt(this.data.eqpttypeid),
        eqptcode: this.data.eqptcode,
        eqptname: this.data.eqptname,
        brandname: this.data.brandname && parseInt(this.data.brandname),
        modelname: this.data.modelname && parseInt(this.data.modelname),
        serialno: this.data.serialno,
        header: this.data.header,
        headerphone: this.data.headerphone,
        manufacturer: this.data.manufacturer,
        purtime: new Date(this.data.purtime),
        supplier: this.data.supplier,
        suppliercontact: this.data.suppliercontact,
        suppliercontactphone: this.data.suppliercontactphone,
        warrantytime: this.data.warrantytime,
        eqptdesc: this.data.eqptdesc,
        eqptstate: this.data.eqptstate,
        customerId: this.data.customerId,
        attachments: this.data.attachments,
        country: this.data.country,
        province: this.data.province,
        city: this.data.city,
        county: this.data.county,
        address: this.data.address
      }
      _this.getEqptType(this.data.eqptsystem)
      _this.getEqptModel(this.data.brandname)
      _this.files = []
      const _attachments = this.data.attachments || ''
      _attachments.split(',').forEach(function(data, index) {
        if (data !== null && data !== '') {
          _this.files.push({ name: data, url: '/api/picture/' + data })
        }
      })
      _this.dialog = true
    }
  }
}
</script>

<style scoped>
  div{
    display: inline-block;
    margin-right: 3px;
  }
</style>
